(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('cda.popup.sitetplGroupViewController', sitetplGroupViewController);
	sitetplGroupViewController.$inject = [ '$scope', '$timeout', '$q', '$uibModalInstance', 'Constants', 'dialogsModule', 'gridService', 'modalService', 'layoutConfig' , 'authService', 'ajaxServiceFactory', 'validatorConfig', 'arithService'];
	function sitetplGroupViewController($scope, $timeout, $q, $uibModalInstance, Constants, dialogsModule, gridService, modalService, layoutConfig, authService, ajaxServiceFactory, validatorConfig, arithService) {
		var ctrl = this, log = $scope.loggerFactory.getLogger("sitetplGroupViewController"), ajaxService = ajaxServiceFactory.buildAjaxService({
		});
		ctrl.dialogsModule = dialogsModule;
//		ctrl.layoutConfig = layoutConfig;
		ctrl.validatorConfig = validatorConfig;
		ctrl.sitetplGroup = {};
		ctrl.formName = "sitetplGroupForm";
		
		ctrl.init = function() {
			ctrl.sitetplGroupRoleInnerGridOptions = gridService.createInnerGridOptions($scope, layoutConfig.formConfigs.sitetplGroupRole.tableConfigs.table, ctrlProfLimitFaciAttrRowSelectionChanged);
			ctrl.sitetplGroupRoleInnerGridOptions.data = 'vm.sitetplGroup.sitetplGroupRoles';
			ctrl.sitetplGroupRoleInnerGridOptions.verifyData = 'vm.sitetplGroupOld.sitetplGroupRoles';
			ctrl.sitetplGroupRoleInnerGridOptions.enableRowHeaderSelection = false;
			function ctrlProfLimitFaciAttrRowSelectionChanged(eventRow, selectedRows) {
				ctrl.selectedProfLimitFaciAttrs = selectedRows;
			}
			// init general
			var initSitetplGroup = ctrl.dialogsModule.params.sitetplGroup || {};
			ctrl.layoutConfig = layoutConfig;
			$timeout(function() {
				ctrl.sitetplGroup = initSitetplGroup;
				ctrl.sitetplGroupOld = ctrl.dialogsModule.params.sitetplGroupOld;
				if (ctrl.sitetplGroupOld)
					ctrl.sitetplGroupOld.sitetplGroupRoles = ctrl.sitetplGroupOld.sitetplGroupRoles || [];
			});
		};
		
		ctrl.close = function() {
			if (!dialogsModule.btnCallback || !dialogsModule.btnCallback['close'] || dialogsModule.btnCallback['close']() !== false) {
				$uibModalInstance.dismiss();
			}
		};
		
	}
})(angular);
